/**
 * Created by user on 2018/5/4.
 */
import { routerRedux } from 'dva/router'
export default {
  namespace: 'app',
  state: {
    isAuth: true,
    collapsed: false
  },
  effects: {
    * query({ payload }, { call ,put, select }) {
      const { isAuth } = yield select(_ => _.app)
      const { pathname } = payload
      if (pathname !== '/login' && !isAuth) {
        yield put(routerRedux.push('/login'))
      }
    }
  },
  subscriptions: {
    setup({ dispatch, history }) {
      history.listen((location) => {
        dispatch({type: 'query', payload: location})
      })
    }
  },
  reducers: {
    switchSider(state) {
      return {
        ...state,
        collapsed: !state.collapsed
      }
    }
  }

};
